
cc.Class({
    extends: cc.Component,

    properties: {
        pokerSprite:{
            default:null,
            type:cc.Sprite
        },

        indicatorNode:{
            default:null,
            type:cc.Node
        },

        indicatorPokerSprite:{
            default:null,
            type:cc.Sprite
        }
    },

    // LIFE-CYCLE CALLBACKS:

    onLoad () {
        cc.gg.registeListener("data_finish_one",this._initDiscardPoker.bind(this),this)
        cc.gg.registeListener("ui_clear_finish_slot",this.resetFinishSlot.bind(this),this)
        cc.find("Canvas").on("player_discard_passive",this.hideIndicator.bind(this),this)

        this.indicatorNode.active = false
    },

    start () {

    },

    // update (dt) {},

    resetFinishSlot:function () {
        this.pokerSprite.spriteFrame = null
        this.pokerSprite.node.active = false
    },

    showIndicator:function (frame) {
        this.indicatorNode.active = true
        this.indicatorPokerSprite.spriteFrame = frame
    },

    hideIndicator:function () {
        this.indicatorNode.active = false
        this.indicatorPokerSprite.spriteFrame = null
    },

    _initDiscardPoker:function (pokerObj) {
        let path
        if(!pokerObj){
            this.pokerSprite.node.active = true
            path = "poker_back"
        }else {
            this.pokerSprite.node.active = true
            let pokerId = pokerObj.poker

            path = cc.gg.resUtil.getPokerFramePath(pokerId)
        }

        cc.loader.loadRes("pokers/"+path,cc.SpriteFrame,function (err, frame) {
            if(err){
                cc.error(err)
                return
            }

            this.pokerSprite.spriteFrame = frame
        }.bind(this))
    },
});
